package com.mysoft.gfyx.common.util.impl;

import com.mysoft.gfyx.common.util.OpportunityUtil;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

@Service
public class OpportunityUtilImpl implements OpportunityUtil {
    public String getStatusFromEndTime(String endTime) {
        String status = "-";
        if (!Objects.equals(endTime, "")) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date deadline = null;
            try {
                deadline = simpleDateFormat.parse(endTime);
                if (deadline.getTime() > new Date().getTime()) {
                    status = "进行中";
                } else {
                    status = "已截止";
                }
            } catch (ParseException e) {
                status = "-";
            }
        } else {
            status = "-";
        }

        return status;
    }
}
